﻿using System;
using System.Collections.Generic;

using Apache.Cassandra;

namespace RexToy.Cassandra
{
    //TODO:Add more parameter null check.
    internal static class Utils
    {
        public static ColumnParent CreateColumnParent(string columnFamily)
        {
            ColumnParent parent = new ColumnParent();
            parent.Column_family = columnFamily;
            return parent;
        }

        public static ColumnParent CreateColumnParent(string columnFamily, byte[] superColumn)
        {
            ColumnParent parent = new ColumnParent();
            parent.Column_family = columnFamily;
            parent.Super_column = superColumn;
            return parent;
        }

        public static ColumnPath CreateColumnPath(string columnFamily, byte[] column)
        {
            ColumnPath path = new ColumnPath();
            path.Column_family = columnFamily;
            path.Column = column;
            return path;
        }

        public static ColumnPath CreateColumnPath(string columnFamily, byte[] superColumn, byte[] column)
        {
            //Note:column is nullable.
            ColumnPath path = new ColumnPath();
            path.Column_family = columnFamily;
            path.Super_column = superColumn;
            path.Column = column;
            return path;
        }

        public static SlicePredicate CreateSlicePredicate(byte[] start, byte[] finish, int count = 10, bool reversed = false)
        {
            SlicePredicate predicate = new SlicePredicate();
            SliceRange range = new SliceRange();
            range.Start = start;
            range.Finish = finish;
            range.Reversed = reversed;
            range.Count = count;
            predicate.Slice_range = range;
            return predicate;
        }

        public static KeyRange CreateKeyRange(byte[] start, byte[] finish, int count = 100)
        {
            KeyRange range = new KeyRange();
            range.Start_key = start;
            range.End_key = finish;
            range.Count = count;
            return range;
        }
    }
}
